package com.shi.yibanjia.controller;

import com.shi.yibanjia.common.Result;
import com.shi.yibanjia.util.AliYunOSSUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "文件上传和下载")
@RestController
@RequestMapping("/admin/file")
public class FileController {


    @RequestMapping("/upload")
    public Result upload(MultipartFile file) {
        return Result.ok(AliYunOSSUtil.putObject(file));
    }

    @DeleteMapping("/fileRemove")
    public Result remove(@RequestBody String url) {
        AliYunOSSUtil.removeObject(url.replace(AliYunOSSUtil.getBaseUrl(), ""));
        return Result.ok();
    }

}
